Embodiments of the present invention relate to methods of developing object oriented programs and to systems that execute object oriented programs.
An object oriented program is a computer program that has been written in a computer programming language having semantics for describing software components designed to cooperate by passing messages between them. Such a computer program defines the overall program behavior as a combination of the behavior of so-called xe2x80x9cobjectsxe2x80x9d. An object is an association of data structure and behavior. An object oriented program may employ multitasking program behavior.
Although the computer that performs an object oriented program may have only one central processing unit for the execution of only one instruction at a time, some of the instructions of each object may be executed in turn in slices according to known techniques of time sharing.
An object oriented program may appear to be responsive to a wider range of inputs than a conventional non-object oriented program for providing the same overall behavior. Programmers have found that for complex behavior, a program developed using object oriented programming techniques is more likely to provide correct behavior in response to a particular sequence of inputs from a wide range of inputs too numerous to test in all combinations.
The semantics of an object oriented programming language permit the description of a program having multiple objects, each operating with its own values. For example, a display of multiple circles being continuously and seemingly simultaneously redrawn at random times with random positions and sizes may be defined by an object oriented program with multiple objects, each object having the function to draw one circle, and each operating with exclusive access to its own variables. As seen by the central processing unit (CPU), the behavior of an object is expressed as a sequence of instructions in the executable instruction code appropriate for the CPU fetched from specific addresses in memory. Such instructions cause the CPU to read and modify the values of numerous variables at specific addresses in the memory. To achieve seemingly simultaneous redrawing of circles, execution of each object is restricted to a time slice. Because a time slice may lapse at any moment during the sequence being performed by one of the circle drawing objects, data describing the position in the instruction sequence (a thread) must be saved and later referred to by the CPU to continue a particular circle when that particular object is given another time slice.
Each object has behavior and state. The functions (i.e., operations or services) of an object are called its behavior. The data describing values of variables and the data describing the position in the instruction sequence are collectively called the object""s state. An object oriented program defines in a program specification the behavior of each unique object and the variables needed for its functions. This definition is, in some programming languages, called a class from which one or more instances of the object may be set in motion (e.g., instantiated).
Complex programs are typically written in modules, sometimes called packages. The definition given by the programmer in all of the modules taken together is compiled one module at a time and then the results of compilation are linked to form executable code with specific references to memory addresses. Linking may be delayed to a time just before the objects of a particular module are needed.
In operation, memory is allocated for the state of each instance of each object. Continuing with the display example above, because all of the circle drawing objects have the same behavior, the memory may contain, at a particular time, one copy of the circle drawing behavior (e.g., instruction code for a method specification of a class) used by all of the circle drawing objects; and, one copy of the circle drawing state (e.g., defined by prototype in the class) for each instance of a circle drawing object.
When teams of programmers develop, over a period of years, products that include computer programs, it is desirable to include in a next product the tested behaviors of some of the previously developed objects. However, such objects may include functions that have not been independently defined, for example, because sharing of data between functions was implemented with references to one or more variables outside the objects"" state. Without a simple method for establishing independence between modules, costly rewriting of each behavior of each module to be included in the next product may be unavoidable. The time and expense of such an undertaking may prevent some products from being brought to market. Consequently, the extent and pace of competition are constrained and benefits to society do not materialize.
A memory, according to various aspects of the present invention, has indicia of an object oriented program that in operation provides indicia of a state. The state includes two instances of a factory and two instances of an object. The first instance of the factory includes a first instance variable. The second instance of the factory includes a second instance variable. The first instance variable is responsive to either the instantiation of the first object by the factory or responsive to an operation of the first object. The second instance variable is responsive to either the instantiation of the second object by the second factory or responsive to an operation of the second object. The first instance variable is independent of both the instantiation of the second object and the operation of the second object.
When, for example, the first and second instance variables of the respective factories respond to the instantiation of the first and second objects, each factory consequently maintains a count of the number of objects it has instantiated. Each object may read the respective number of instances that applies to its factory. By implementing a count of instances as an instance variable of a respective factory, as opposed to a static variable of the object""s class, the first and the second object may execute independently of each other. As another example, when the execution environment includes a JAVA virtual machine (JVM) that supports a single processing space, independent execution as described above permits multiple application programs to be concurrently executed by the JVM.
A printer, according to various aspects of the present invention, includes a print engine, a processor, and a memory. The processor provides data to the print engine. The memory has indicia of an object oriented program executed by the processor to provide indicia of a state as discussed above. When, for example, the first and second instance variables of the respective factories respond respectively to operations of the objects, each object may use its factory""s instance variable independently of the operations of the other object. As another example, when the execution environment includes a JAVA virtual machine (JVM) that supports a single processing space, independent execution as described above permits multiple application programs to independently use the behavior of the same library object with independent states.
A method, according to various aspects of the present invention, for integrating a first program specification with application program specifications includes two steps performed in any order. The first specification includes references to static data. The resulting integration is operative in an environment, for example a JVM as discussed above. In one of the steps, a revised first specification is prepared wherein the revised first specification includes a factory specification; the factory is specified to perform object instantiation in accordance with the revised first specification; and the factory specification defines factory instance data. In the other step, a first reference to the static data is replaced with a second reference to the factory instance data; and, each application specification is prepared so that a factory object instantiated in accordance with the factory specification responds to each request for instantiation of a respective object of the first revised specification.
The revision to the first specification and the criteria for revising (or initially writing) application specifications provides for concurrent application execution in a manner that is considerably simpler than, for example, modifying the execution environment to permit multiple separate processing spaces. The capability to perform multiple application programs is supported with no change to the processing environment. For example, when applied to the specifications of object oriented programs to be executed by a JVM as discussed above, the resulting integration will operate on one unmodified JVM intended for single process execution. The expense of providing a JVM for each application specification may be avoided.